package com.coocaa.internship.dao;

import com.coocaa.internship.pojo.PositionList;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author :hhd
 * @Description:
 * @date :2019/8/8 8:52
 */
@Mapper
@Component
public interface PositionListDao {
    String TABLE_NAME = "position_info left join company on position_info.company_id = company.company_id";

    String SELECT_FIELDS = "position_id, position_name, position_label, position_info.company_id, position_area, " +
            "position_duration, company_name, company_logo, publish_time";

    @Select({"select", SELECT_FIELDS, "from", TABLE_NAME})
    List<PositionList> selectAllPositionList();

    @Select({"select", SELECT_FIELDS, "from", TABLE_NAME, "where position_name like #{positionName}"})
    List<PositionList> selectPositionListByPositionName(@Param("positionName") String positionName);

    @Select({"select", SELECT_FIELDS, "from", TABLE_NAME, "where position_area = #{positionArea}"})
    List<PositionList> selectPositionListByPositionArea(@Param("positionArea") String positionArea);

    @Select({"select", SELECT_FIELDS, "from", TABLE_NAME, "where position_name like #{positionNameOrCompany} " +
            "or Company_name like #{positionNameOrCompany}"})
    List<PositionList> selectPositionListByPositionNameOrCompany(@Param("positionNameOrCompany") String positionNameOrCompany);

    @Select({"select", SELECT_FIELDS, "from", TABLE_NAME, "where position_type = #{positionType}"})
    List<PositionList> selectPositionListByPositionType(@Param("positionType") String positionType);

    @Select({"<script> select", SELECT_FIELDS, "from", TABLE_NAME, "<foreach item = 'item_id' index = 'index'" +
            " collection = 'ids' open='where position_id in (' separator=',' close=')'> #{item_id} </foreach> </script>"})
    List<PositionList> selectPositionListByIds(@Param("ids") List<Long> ids);
}
